package com.ws.admin.help.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.ws.common.base.BaseUtils;
import com.ws.common.constant.BaseConstants;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ws.admin.help.entity.Help;
import org.springframework.web.bind.annotation.RestController;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ws.common.result.entity.ResultEntity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import com.ws.admin.help.service.IHelpService;
import com.ws.common.base.BaseController;

/**
 * <p>
 * 求助信息表 前端控制器
 * </p>
 *
 * @author weifucheng
 * @since 2019-11-26
 */
@RestController
@RequestMapping("/help")
public class HelpController extends BaseController<Help> {

    @Autowired
    private IHelpService helpService;

    @RequestMapping("/list")
    public ResultEntity list(Help help, Integer current, Integer size){
        return ResultEntity.succes(helpService.list(help, current, size));
    }

    @RequestMapping("/readByMap")
    public ResultEntity readByMap(Help help){
        return ResultEntity.succes(helpService.readByMap(BeanUtil.toBean(help, HashMap.class)));
    }

    @RequestMapping("/save")
    public ResultEntity save(Help help){
        BaseUtils.setDefault(help);
        if(StrUtil.isEmpty(help.getAuditResult())){
            help.setAuditResult(BaseConstants.AUDIT_RESULT_PENGDING);
        }
        return ResultEntity.succes(iService.saveOrUpdate(help));
    }
}
